import 'package:amap_location_fluttify/amap_location_fluttify.dart';
import 'package:fluro/fluro.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBBaseRouter.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNoSplashFactory.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBUtils/YBTabBarMainModule/YBTabBarMainPage.dart';
import 'dart:io';
import 'YBRefreshScrollBehavior.dart';
import 'package:flutter_localizations/flutter_localizations.dart';


/*
本项目只使用于安卓项目，iOS一切原生的原生信息全部没有配置，微信，相机等权限，一些其他不确定信息都没有配置
* */

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SpUtil.getInstance();
  await AmapLocation.instance.init(iosKey: "ed21ead60c7b3fd6c9f40c2638d28bf5");
  runApp(MyApp());
  configLoading();
  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
      systemNavigationBarColor:Color(0xFF000000),
      systemNavigationBarDividerColor: null,
      statusBarColor:YBColor.white,
      systemNavigationBarIconBrightness: Brightness.light,
      statusBarIconBrightness: Brightness.dark,
      statusBarBrightness: Brightness.light,
    );
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
  setDesignWHD(414.0,896.0, density:2);
}

//loading
void configLoading(){
  EasyLoading.instance
    ..displayDuration = Duration(milliseconds: 2000)
    ..indicatorType = EasyLoadingIndicatorType.fadingCircle
    ..loadingStyle = EasyLoadingStyle.dark
    ..indicatorSize = 45.0
    ..radius = 10.0
    ..progressColor = YBColor.commonThemeColor
    ..backgroundColor = Colors.black
    ..maskColor = Colors.black.withOpacity(0.2)
    ..userInteractions = true;
}


class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}


class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
    _initFluWx();
  }

  @override
  Widget build(BuildContext context) {

    final router = FluroRouter();
    YBBaseRouter.configureRoutes(router);
    YBApplication.router = router;

    return RefreshConfiguration(
      footerTriggerDistance: YBTextStyle.adapterSize15,
      dragSpeedRatio: 0.9,
      headerBuilder:() => WaterDropHeader(),
      footerBuilder:() => ClassicFooter(
        loadStyle: LoadStyle.ShowWhenLoading,
      ),
      enableLoadingWhenNoData: false,
      enableLoadingWhenFailed: true,
      shouldFooterFollowWhenNotFull: (state){
        return false;
      },
      child:  MaterialApp(
        theme: ThemeData(
          primaryColor: YBColor.white,
          visualDensity: VisualDensity.adaptivePlatformDensity,
          splashColor: Color(0x66C8C8C8),
          highlightColor: Colors.transparent,
          splashFactory: const YBNoSplashFactory(),
        ),
        onGenerateRoute: YBApplication.router.generator,
        debugShowCheckedModeBanner: false,

        localizationsDelegates: [
          RefreshLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalMaterialLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate
        ],
        supportedLocales: [
          const Locale('zh'),
        ],
        locale: const Locale('zh'),
        localeResolutionCallback:(Locale locale, Iterable<Locale> supportedLocales){
           return locale;
        },
        home: YBTabBarMainPage(),
        builder:(BuildContext context,Widget child){
          return FlutterEasyLoading(child: ScrollConfiguration(
            child: child,
            behavior:YBRefreshScrollBehavior(),
          ));
        },
      ),
    );
  }


  _initFluWx() async {
    await fluwx.registerWxApi(
      appId: "wx88424b837bdd4e7e",
      doOnAndroid: true,
      doOnIOS: true,
      universalLink: "https://app.ubzone.cn/"
    );

    var result = await fluwx.isWeChatInstalled;
    print('安装了吗？有没有$result');
  }

}


